1
|
|
|
import {MigrationInterface, QueryRunner} from "typeorm"; |
2
|
|
|
|
3
|
|
|
export class Quote1586090806067 implements MigrationInterface { |
4
|
|
|
name = 'Quote1586090806067' |
5
|
|
|
|
6
|
|
|
public async up(queryRunner: QueryRunner): Promise<any> { |
7
|
|
|
await queryRunner.query(`CREATE TABLE "quote" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "number" character varying NOT NULL, "date" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, "expiryDate" TIMESTAMP NOT NULL, "ownerId" uuid NOT NULL, "customerId" uuid NOT NULL, "projectId" uuid, CONSTRAINT "PK_b772d4cb09e587c8c72a78d2439" PRIMARY KEY ("id"))`, undefined); |
8
|
|
|
await queryRunner.query(`CREATE TABLE "quote_history" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "status" character varying NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, "quoteId" uuid NOT NULL, "ownerId" uuid NOT NULL, CONSTRAINT "PK_15e7cbdd8d80ae8e44edc4369a4" PRIMARY KEY ("id"))`, undefined); |
9
|
|
|
await queryRunner.query(`CREATE TABLE "quote_item" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "title" character varying NOT NULL, "quantity" integer NOT NULL, "dailyRate" integer NOT NULL, "vat" integer NOT NULL, "quoteId" uuid NOT NULL, CONSTRAINT "PK_a491f996b20f4b5110ec480e6bc" PRIMARY KEY ("id"))`, undefined); |
10
|
|
|
await queryRunner.query(`ALTER TABLE "quote" ADD CONSTRAINT "FK_d0a82ae7e4d8ba9e9b7337d3982" FOREIGN KEY ("ownerId") REFERENCES "user"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, undefined); |
11
|
|
|
await queryRunner.query(`ALTER TABLE "quote" ADD CONSTRAINT "FK_588da10cc115a4d5c4af2955062" FOREIGN KEY ("customerId") REFERENCES "customer"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, undefined); |
12
|
|
|
await queryRunner.query(`ALTER TABLE "quote" ADD CONSTRAINT "FK_acd0da7cbdbc23c5a47318202a7" FOREIGN KEY ("projectId") REFERENCES "project"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, undefined); |
13
|
|
|
await queryRunner.query(`ALTER TABLE "quote_history" ADD CONSTRAINT "FK_42fc2528e6952dfaed66175e7e3" FOREIGN KEY ("quoteId") REFERENCES "quote"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, undefined); |
14
|
|
|
await queryRunner.query(`ALTER TABLE "quote_history" ADD CONSTRAINT "FK_374cb8bc36df5b7ec0b7bdec90b" FOREIGN KEY ("ownerId") REFERENCES "user"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, undefined); |
15
|
|
|
await queryRunner.query(`ALTER TABLE "quote_item" ADD CONSTRAINT "FK_6296266787152fd91f74cb9d1d1" FOREIGN KEY ("quoteId") REFERENCES "quote"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, undefined); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public async down(queryRunner: QueryRunner): Promise<any> { |
19
|
|
|
await queryRunner.query(`ALTER TABLE "quote_item" DROP CONSTRAINT "FK_6296266787152fd91f74cb9d1d1"`, undefined); |
20
|
|
|
await queryRunner.query(`ALTER TABLE "quote_history" DROP CONSTRAINT "FK_374cb8bc36df5b7ec0b7bdec90b"`, undefined); |
21
|
|
|
await queryRunner.query(`ALTER TABLE "quote_history" DROP CONSTRAINT "FK_42fc2528e6952dfaed66175e7e3"`, undefined); |
22
|
|
|
await queryRunner.query(`ALTER TABLE "quote" DROP CONSTRAINT "FK_acd0da7cbdbc23c5a47318202a7"`, undefined); |
23
|
|
|
await queryRunner.query(`ALTER TABLE "quote" DROP CONSTRAINT "FK_588da10cc115a4d5c4af2955062"`, undefined); |
24
|
|
|
await queryRunner.query(`ALTER TABLE "quote" DROP CONSTRAINT "FK_d0a82ae7e4d8ba9e9b7337d3982"`, undefined); |
25
|
|
|
await queryRunner.query(`DROP TABLE "quote_item"`, undefined); |
26
|
|
|
await queryRunner.query(`DROP TABLE "quote_history"`, undefined); |
27
|
|
|
await queryRunner.query(`DROP TABLE "quote"`, undefined); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
} |
31
|
|
|
|